<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Carbon\Carbon;

class TeamUserResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        
        $isnew = Carbon::now() < $this->bind_at?1:0;

        return [
            'id'   => (string)$this->id,
            'fromid' => $this->fromid,
            'ancestorid' => $this->ancestorid,
            'name' => $this->name,
            'avatar' => $this->avatar,
            'bind_at' => $this->bind_at,
            'effective_at' => $this->effective_at,
            'isnew' => $isnew,
            'time' => $this->created_at->from(),
        ];
    }
}
